home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / VECTOR.CPP < prev    next >
Text File  |  1997-05-06  |  765b  |  42 lines

  1.  #include <vector>
  2.  
  3.  using namespace std;
  4.  
  5.  ostream& operator<< (ostream& out, const vector<int>& v)
  6.  {
  7.    copy(v.begin(), v.end(), ostream_iterator<int>(out," "));
  8.    return out;
  9.  }
  10.  
  11.  int main ()
  12.  {
  13.    //
  14.    // Create a vector of doubles, and one of integers.
  15.    //
  16.    vector<int>         vi;
  17.    int                 i;
  18.  
  19.    for (i = 0; i < 10; ++i)
  20.      //
  21.      // Insert values before the beginning.
  22.      //
  23.      vi.insert(vi.begin(), i);
  24.    //
  25.    // Print out the vector.
  26.    //
  27.    cout << vi << endl;
  28.    //
  29.    // Now let's erase half of the elements.
  30.    //
  31.    int half = vi.size() / 2;
  32.  
  33.    for (i = 0; i < half; ++i)
  34.      vi.erase(vi.begin());
  35.    //
  36.    // Print it out again.
  37.    //
  38.    cout << vi << endl;
  39.  
  40.    return 0;
  41.  }
  42.